/**
 * 
 */
package org.meruvian.yama.struts.converter;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;
import java.util.Map;

import org.apache.struts2.util.StrutsTypeConverter;

/**
 * @author Dian Aditya
 * 
 */
public class DateConverter extends StrutsTypeConverter {

	@Override
	public Object convertFromString(Map context, String[] values, Class toClass) {
		if (values == null)
			return null;
		
		System.out.println(values + " HAHAHAHAAH");
		
		SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd");

		try {
			Date[] dates = new Date[values.length];

			for (int i = 0; i < values.length; i++) {
				dates[i] = dateFormat.parse(values[i]);
			}

			return dates.length == 1 ? dates[0] : dates;
		} catch (ParseException e) {
			return null;
		}
	}

	@Override
	public String convertToString(Map context, Object o) {
		return null;
	}

}
